﻿/**
 * @file setting_about.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_watch.h"

#if USE_LV_WATCH_SETTING_ABOUT != 0

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/
typedef struct {
    lv_cont_ext_t oldext;
    uint8_t       click_count;
} lv_setting_about_ext_t;

/**********************
 *  STATIC PROTOTYPES
 **********************/
static void setting_about_click_event_cb(lv_obj_t * obj, lv_event_t e);
static lv_obj_t * setting_about_create(lv_obj_t * activity_obj);
static void setting_about_prepare_destory(lv_obj_t * activity_obj);

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
***********************/
void setting_about_create_btn_action(lv_obj_t * btn, lv_event_t event)
{
    (void)btn;

    if(LV_EVENT_CLICKED != event) return;

    lv_watch_png_cache_all_free();

    lv_obj_t * obj = setting_about_create(NULL);
    LV_ASSERT_MEM(obj);
    if(obj == NULL) return;
}

/**********************
 *   STATIC FUNCTIONS
 **********************/
static lv_obj_t * setting_about_create(lv_obj_t * activity_obj)
{
    char model_str[20] = {};
    char version_str[40] = {};

    if(NULL == activity_obj) {
        lv_watch_activity_ext_t activity_ext;
        memset(&activity_ext, 0, sizeof(lv_watch_activity_ext_t));
        activity_ext.actId = ACT_ID_SETTING_ABOUT;
        activity_ext.create = setting_about_create;
        activity_ext.prepare_destory = setting_about_prepare_destory;
        activity_obj = lv_watch_creat_activity_obj(&activity_ext);
        LV_ASSERT_MEM(activity_obj);
        if(NULL == activity_obj) {
            return NULL;
        }
    }

    lv_obj_t * obj = lv_watch_obj_create(activity_obj);
    LV_ASSERT_MEM(obj);
    if(NULL == obj) {
        return NULL;
    }

    lv_obj_t * content = lv_cont_create(obj, NULL);
    lv_obj_set_size(content, lv_obj_get_width(obj), lv_obj_get_height(obj));
    lv_obj_add_style(content, LV_CONT_PART_MAIN, &lv_watch_style_transp);
    lv_obj_align(content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
    lv_obj_set_click(content, true);
    lv_setting_about_ext_t * about_ext = lv_obj_allocate_ext_attr(content, sizeof(lv_setting_about_ext_t));
    about_ext->click_count = 0;

    lv_obj_t * title_label = lv_label_create(content, NULL);
    lv_obj_add_style(title_label, LV_LABEL_PART_MAIN, &lv_watch_font20_gray);
    lv_label_set_align(title_label, LV_LABEL_ALIGN_CENTER);
    lv_obj_set_click(title_label, false);
    lv_label_set_text_id(title_label, WATCH_TEXT_ID_ABOUT_WATCH);
    lv_obj_align(title_label, content, LV_ALIGN_IN_TOP_MID, 0, 10);

    lv_obj_t * model_label = lv_label_create(content, NULL);
    lv_obj_add_style(model_label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_label_set_align(model_label, LV_LABEL_ALIGN_CENTER);
    lv_obj_set_click(model_label, false);

    lv_obj_t * version_label = lv_label_create(content, NULL);
    lv_obj_add_style(version_label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_label_set_align(version_label, LV_LABEL_ALIGN_CENTER);
    lv_obj_set_click(version_label, false);
    lv_obj_set_base_dir(version_label, LV_BIDI_DIR_LTR);

    snprintf(model_str, 20, "%s:%s", (char *)lv_lang_get_text(WATCH_TEXT_ID_MODE), app_adaptor_get_model_id());
    snprintf(version_str, 50, "%s:\n%s", (char *)lv_lang_get_text(WATCH_TEXT_ID_VERSION_NUM), app_adaptor_get_version());


    lv_label_set_text(model_label, model_str);
    lv_obj_align(model_label, content, LV_ALIGN_IN_TOP_MID, 0, 80);
    lv_label_set_long_mode(version_label,LV_LABEL_LONG_BREAK);
    lv_obj_set_width(version_label,200);
    lv_label_set_text(version_label, version_str);
    lv_obj_align(version_label, content, LV_ALIGN_IN_TOP_MID, 0, 105);

    lv_obj_set_event_cb(content, setting_about_click_event_cb);
    lv_watch_obj_add_element(content);
#if USE_LV_WATCH_DUMMY_SMS
    MMI_Modem_Ims_Vops_Ind(1,1);//dummy test data
#endif
    return obj;
}

static void setting_about_prepare_destory(lv_obj_t * activity_obj)
{

}

static void setting_about_click_event_cb(lv_obj_t * obj, lv_event_t e)
{
    lv_setting_about_ext_t * about_ext = (lv_setting_about_ext_t *)lv_obj_get_ext_attr(obj);

    if(LV_EVENT_CLICKED == e) {
        about_ext->click_count++;
        if(7 == about_ext->click_count) {
            about_ext->click_count = 0;
            factorymode_main_create(NULL);
        }
    }
}

#endif /*USE_LV_WATCH_SETTING_ABOUT*/
